#!/bin/bash
#
# Xiange Linux build scripts

# Short one-line description of this package.
DESCRIPTION=" snmp agent"

# Homepage, not used by Portage directly but handy for developer reference
HOMEPAGE="http://ops.dev.shopex.cn/"

# Point to any required sources; these will be automatically downloaded by
# gpkg. 
# $N = package name, such as autoconf, x-org
# $V = package version, such as 2.6.10

#SRC_URI="http://foo.bar.com/$N-$V.tar.bz2"
SRC_URI=""


# Binary package URI.
BIN_URI=""


# Runtime Depend
RDEPEND=""

# Build time depend
DEPEND="${RDEPEND}"



#init 
xgb_init()
{
	echo "init $N-$V$R build script..."
}

#unpack
xgb_unpack()
{
    return 0
}

#config
xgb_config()
{
    return 0
}

#build
xgb_build()
{
    return 0
}

#check
xgb_check()
{
	echo "checking $N-$V$R.."
	#make check
}

#install
xgb_install()
{
    echo "install to $XGPATH_DEST..."
    #install everything to $XGPATH_DEST
    yum -y remove net-snmp  net-snmp-utils
    yum -y install net-snmp  net-snmp-utils
    mkdir -pv  $XGPATH_DEST/etc/snmp
    cat >  $XGPATH_DEST/etc/snmp/snmpd.conf << EOF
com2sec notConfigUser default SNMP_PASSWORD 
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser 
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1 
access notConfigGroup "" any noauth exact all none none
view all included .1 80
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
view all included .1
EOF

}

#post install
xgb_postinst()
{
   
    SNMP_PASSWORD=$(</dev/urandom tr -dc A-Za-z0-9 | head -c8)
    sed -i s,SNMP_PASSWORD,$SNMP_PASSWORD,g  /etc/snmp/snmpd.conf
    if [ $? -eq 0 ]; then
        sed -i /snmp:default:/d $XGPATH/password.txt
        echo "snmp:default:"$SNMP_PASSWORD >> $XGPATH/password.txt
    fi
    chkconfig --add snmpd 
    service snmpd start    
    snmpwalk -c $SNMP_PASSWORD -v 1 -m ALL localhost
}

#pre remove
xgb_prerm()
{
	echo "running before package delete..."
}

#post remove
xgb_postrm()
{
	echo "running after package delete..."
}
